Editor.Resource = function () {
	var shape;
	var element;
	var deckEdit;	
	var impl;
	return {
		init: function (u,i) {
			shape = new Editor.Shape();
			if (i != undefined) {
				impl = i;
			} else {
				impl = this;
			}
			shape.init(impl,u);
			element = new Editor.Element();
			element.init();
			shape._resize(Editor.CONFIG.RESOURCE_SHAPE_WIDTH, Editor.CONFIG.RESOURCE_SHAPE_HEIGHT);
			deckEdit = new Editor.DeckEdit();
			deckEdit.init(shape);
		},
		getInfo: function () {
			var prefix = element.getNamespace().getPrefix();
			var uri = element.getNamespace().getUri();
			var str = '';
			if (Editor.CONFIG.DEBUG) {
				var str = 'Resource:\n';
			}
			if (prefix != '' && uri != '') {
				str += prefix + ' = ' + uri;
			} else {
				str += 'no namespace';
			}
			if (Editor.CONFIG.DEBUG) {
				str += '\n( x:' + impl.getX();
				str += ' ; y:' + impl.getY();
				str += ' ; w:' + impl.getWidth();
				str += ' ; h:' + impl.getHeight() + ' )';
				str += '\nuuid: ' + impl.getUuid();
			}
			return str;
		},
		getNamespace: function () {
			return element.getNamespace();
		},
		setNamespace: function (n) {
			element.setNamespace(n);
		},
		getName: function () {
			return element.getName();
		},
		setName: function (n) {
			element.setName(n);
		},
		getText: function () {
			var t = element.getNamespace().getPrefix();
			if (t == '') {
				t = '<' + element.getName() + '>';
			} else {
				t = element.getNamespace().getPrefix() + ':' + element.getName();
			}
			return t;
		},
		_remove: function () {
			shape._remove(impl);
			deckEdit.remove();
		},
		remove: function () {
			shape.remove(impl);
			deckEdit.remove();
		},
		draw: function () {
			shape.draw(impl);
			deckEdit.draw();
			deckEdit.redraw();
		},
		toFront: function () {
			shape.toFront(impl);
			deckEdit.toFront(impl);
		},
		moveTo: function (x, y) {
			shape.moveTo(x, y);
		},
		translate: function (dx, dy) {
			shape._translate(dx,dy);
			deckEdit.translate(dx,dy);
		},
		_translate: function (dx, dy) {
			shape._translate(dx,dy);
			deckEdit.translate(dx,dy);
		},
		_resize: function (dw, dh) {
			shape._resize(dw, dh);
			deckEdit.redraw();
		},
		resize: function (dw, dh) {
			shape.resize(dw, dh);
			deckEdit.redraw();
		},
    getTextAttr: function () {
      return Editor.CONFIG.SHAPE_ATTR_TEXT;
    },
		figure: function () {
			return Editor.STATE.CANVAS.rect(shape.getX(), shape.getY(), shape.getWidth(), shape.getHeight(), Editor.CONFIG.RESOURCE_SHAPE_ROUNDED).
			attr(Editor.CONFIG.RESOURCE_SHAPE_ATTR);
		},
		getShapeAttr: function () {
			return Editor.CONFIG.RESOURCE_SHAPE_ATTR;
		},
		getUuid: function () {
			return shape.getUuid();
		},
		isDeleted: function () {
			return shape.isDeleted();
		},
		getX: function () {
			return shape.getX();
		},
		getY: function () {
			return shape.getY();
		},
		getWidth: function () {
			return shape.getWidth();
		},
		getHeight: function () {
			return shape.getHeight();
		},
		toString: function () {
			return 'Resource-->(' + element.toString() + ' ; ' + shape.toString() + ')'
		},
		select: function () {
			shape.select(impl);
		},
		unselect: function () {
			Editor.Util.unselect(shape);
			shape.unselect();	
		},
		frameResize: function () {
			return shape.frameResize();
		},
		saveIni: function (e) {
			shape.saveIni(e);
		},
		getIniPosx: function () {
			return shape.getIniPosx();
		},
		getIniPosy: function () {
			return shape.getIniPosy();
		},
		mousedown: function (e) {
			if (!Editor.Util.isDragging()) {
				shape.mousedown(e);
			}
		},
		mouseover: function () {
			if (!Editor.Util.isDragging()) {
				shape.mouseover();
				deckEdit.mouseover();
			}
		},
		mouseout: function () {
			if (!Editor.Util.isDragging()) {
				shape.mouseout();
				deckEdit.mouseout();
			}
		},
		click: function () {
			if (!Editor.Util.isDragging()) {
				shape.click();
				deckEdit.toFront();
			}
		},
		updateText: function () {
			shape.updateText();
		},
		getMinWidth: function () {
			return shape.getMinWidth();
		},
		getMinHeight: function () {
			return shape.getMinHeight();
		},
		showEdit: function () {
			Editor.Keys.unbind();
			Editor.STATE.SHAPETOUPDATE = impl;
			$('#name').val(element.getName());
			$('#namespacePrefix').val(element.getNamespace().getPrefix());
			$('#namespaceUri').val(element.getNamespace().getUri());
			$('#dialogAddResource').jqm({overlay: 40, modal: true}).jqmShow();
		},
		getDeckEdit: function () {
			return deckEdit;
		},
		getImplementation: function () {
			return impl;
		},
        onmouseup: function () {
            
        },
		toObject: function () {
			return {
				'element': element.toObject(),
				'shape': shape.toObject()
			}
		}
	}
}
